package com.koron.operation.classes.info.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.operation.classes.info.bean.dto.ClassesClassifyDTO;
import com.koron.operation.classes.info.bean.query.ClassesQuery;
import com.koron.operation.classes.info.service.ClassesClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jzp
 * @since 2023/5/25
 */
@Api(tags = "班别分类接口")
@RestController
@RequestMapping("classesClassify")
public class ClassesClassifyController {
    /**
     * 服务对象
     */
    @Autowired
    private ClassesClassifyService classesClassifyService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "分页")
    @GetMapping("page")
    public Response<PageInfo> page(PageQuery pageQuery, ClassesQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesClassifyService, "page", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<ClassesClassifyDTO> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesClassifyService, "getDtoById", ClassesClassifyDTO.class, id));
    }

    @ApiOperation(value = "保存或更新数据")
    @PostMapping
    public Response<String> save(@RequestBody ClassesClassifyDTO classesClassifyDTO) {
        ADOConnection.runTask(getCurrDs(), classesClassifyService, "saveOrUpdateDto", Boolean.class, classesClassifyDTO);
        return Response.ok(classesClassifyDTO.getId());
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping
    public Response<String> delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), classesClassifyService, "deleteById", Boolean.class, id);
        return Response.ok();
    }

}
